<?php

/**
 * autocomplete actions.
 *
 * @package    sistema_itec_new
 * @subpackage autocomplete
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class ajaxActions extends sfActions {

    /**
     * Executes index action
     *
     * @param sfRequest $request A request object
     */
    public function executeIndex(sfWebRequest $request) {
        $this->forward('default', 'module');
    }
    
    public function executeCohoUdefRel(sfWebRequest $request) {
       $coho_udef = Doctrine::getTable('CohorteUnidadFormacion')->getAllWithDependencies();
       return $this->renderText($coho_udef);
    }
    
    public function executeBarrio(sfWebRequest $request) {
        $this->getResponse()->setContentType('application/json');
        $items = Doctrine::getTable('barrio')
                ->retrieveForSelect($request->getParameter('q'), 10);

        return $this->renderText(json_encode($items));
    }

    public function executeLocalidad(sfWebRequest $request) {
        $this->getResponse()->setContentType('application/json');
        $items = Doctrine::getTable('localidad')
                ->retrieveForSelect($request->getParameter('q'), 10);

        header("Content-Type: application/json");
        return $this->renderText(json_encode($items));
    }
    
    public function executeDepartamento(sfWebRequest $request) {
        $this->getResponse()->setContentType('application/json');
        $items = Doctrine::getTable('departamento')
                ->retrieveForSelect($request->getParameter('q'), 10);

        return $this->renderText(json_encode($items));
    }
    
    public function executeProvincia(sfWebRequest $request) {
        $this->getResponse()->setContentType('application/json');
        $items = Doctrine::getTable('provincia')
                ->retrieveForSelect($request->getParameter('q'), 10);

        return $this->renderText(json_encode($items));
    }
    
    public function executePais(sfWebRequest $request) {
        $this->getResponse()->setContentType('application/json');
        $items = Doctrine::getTable('pais')
                ->retrieveForSelect($request->getParameter('q'), 10);

        return $this->renderText(json_encode($items));
    }
    
    public function executeNacionalidad(sfWebRequest $request) {
        $this->getResponse()->setContentType('application/json');
        $items = Doctrine::getTable('nacionalidad')
                ->retrieveForSelect($request->getParameter('q'), 10);

        return $this->renderText(json_encode($items));
    }

}
